<?php if($_COOKIE["username"] != "hungxd2992"){ header("location: ../../index.php");?>

<?php } ?>
<?php include_once '../include/header.php' ?>
<?php include_once '../../usercontroller.php'; ?>
<div id="panelNav">
    <div id="logo-featured"><img width="60" height="60"  src="../../Images/coupon.png" alt=""/><span>Quản lý thành viên</span></div>
    <ul>
        <li><a class="hover" href="#"><img src="../../Images/icon_delete.png" class="multi_del qTip"  title="Xóa chọn" border="0"/></a></li>
        <li><a class="hover" href="create.php"><img src="../../Images/icon_new.png" class="qTip" title="Thêm dữ liệu" border="0"/></a></li>
    </ul>
</div><!--end #menu_news-->
<div id="content">
    <div id="main-container">
        <div id="filter-bar" title="Filter bar">
            <form action="" method="GET">
                Tìm theo tên thành viên: <input type="text" id="name" name="name" value="<?php echo isset($_GET["name"]) ? $_GET["name"] : "" ?>"/>
                <select onchange="window.location = '?status='+this.value" name="status">
                    <option value="">- Chọn trạng thái -</option>
                    <?php if (isset($_GET["status"]) && $_GET["status"] == 1) { ?>
                        <option selected value="1">Kích hoạt</option>
                        <option value="0">Không kích hoạt</option>
                    <?php } else if (isset($_GET["status"]) && $_GET["status"] == 0) { ?>
                        <option value="1">Kích hoạt</option>
                        <option selected value="0">Không kích hoạt</option>
                    <?php } else if (!isset($_GET["status"]) || empty($_GET["status"])) { ?>
                        <option value="1">Kích hoạt</option>
                        <option value="0">Không kích hoạt</option>
                    <?php } ?>
                </select>
            </form>
        </div>
        <input type="hidden" name="multi_del" id="multi_del" value=""/>
        <table class="mytable" cellspacing="0" style="margin-left:5px;border-collapse: collapse;border:1px solid #CAE8EA;">
            <tr>                
                <th>Avatar</th>
                <th>Tài khoản</th>
                <th>Tên đầy đủ</th>
                <th>Ngày sinh</th>
                <th>Giới tính</th>
                <th>Email</th>
                <th>Số điện thoại</th>
                <th>Yahoo</th>                
                <th>Status</th>
                <th>Chức năng</th>
            </tr>      
            <?php if (!empty($list_user)) { ?>
                <?php foreach ($list_user as $row) { ?>
                    <tr class="user<?php echo $row["id"] ?>">                        
                        <td>
                            <img width="60px" height="60px" class="img-border" src="../../data/avatar/<?php echo $row["avatar"] ?>" alt="<?php echo $row["avatar"] ?>"/>
                        </td>
                        <td>
                            <?php echo $row["username"] ?>
                        </td>
                        <td>
                            <?php echo $row["fullname"] ?>
                        </td>
                        <td>
                            <?php echo $row["ngaysinh"] ?>
                        </td>
                        <td>
                            <?php echo $row["gioitinh"] ?>
                        </td>
                        <td>
                            <?php echo $row["email"] ?>
                        </td>
                        <td>
                            <?php echo $row["sodienthoai"] ?>
                        </td>
                        <td>
                            <?php echo $row["yahoo"] ?>
                        </td>
                        <td>
                            <a class="status" stt="<?php echo $row["status"] ?>" id="<?php echo $row["id"]; ?>"  href="#"><img  src="../../Images/<?php echo (($row["status"] == "1") ? "icon_active.png" : "icon_inactive.png"); ?>"  title='<?php echo (($row["status"] == "1") ? "Đang dùng(Click để thay đổi)" : "Đang ẩn(Click để thay đổi)"); ?>' /></a>
                        </td>
                        <td>
                            <a id="<?php echo $row["id"]; ?>"  class="edit_data" href="edit.php?action=edit&id=<?php echo $row["id"]; ?>"><img alt="" src="../../Images/icon_edit.png" title="Sửa" border="0"/></a>
                            <a id="<?php echo $row["id"]; ?>" class="xoa"><img src="../../Images/icon_del.png"  title="Xóa" border="0"/></a>
                        </td>                
                    </tr>
                <?php } ?>
            <?php } ?>
        </table>        
        <div class="paging" style="text-align: center;margin-top:10px;height:25px;"><?php echo $page->firs_page ?><?php echo $page->previous_page ?><?php echo "$page->page_links"; ?><?php echo $page->next_page ?><?php echo $page->last_page ?></div>
    </div>    
    <script type="text/javascript">               
        if (document.getElementById("name")) {
            document.getElementById("name").onkeydown = function(e) {
                e = e || window.event;
                if (e.keyCode == 13) {
                    window.location = "?name="+$("#name").val();
                    return false;
                }
            };
        }
        $(function(){            
            $(".status").click(function(){
                var stt = $(this).attr("stt");
                var id = $(this).attr("id");
                $.ajax({
                    url:"../../usercontroller.php?action=status",
                    type:"GET",
                    data:{stt:""+stt,id:""+id},
                    success:function(data){
                        if(data == true){
                            location.reload();
                        }
                    }
                });
                return false;
            })
            $(".xoa").click(function(){
                var id = $(this).attr("id");
                if(confirm("Bạn có muốn xóa bản ghi này không?")){
                    $.ajax({
                        url:"usercontroller.php?action=xoa",
                        type:"POST",
                        data:{id:""+id},
                        success:function(data){
                            if(data == true){
                                $(".data"+id).fadeTo("slow", 0);
                                $(".data"+id).css("background","#f00");
                                $(".data"+id).slideUp("slow");
                            }
                        }
                    });
                }
            })                        
        });
    </script>
</div>
<?php include_once '../include/footer.php' ?>